package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Joe
 * Date: 25/06/13
 * Time: 10:58 AM
 * To change this template use File | Settings | File Templates.
 */
public final class LibrarySystem {

    public boolean IsSystemActive;
    private List<Book> books;
    private List<Movie> movies;
    private List<Reservation> reservations;

    private User loggedInUser;

    public LibrarySystem() {
        this.IsSystemActive = true;
        this.books = new ArrayList<Book>();
        this.movies = new ArrayList<Movie>();
        this.reservations = new ArrayList<Reservation>();
        this.loggedInUser = null;
        this.loadBooksIntoMemory();
        this.loadMoviesIntoMemory();
    }

    public void setUser(User user){
        this.loggedInUser = user;
    }

    public User getLoggedInUser(){
        return this.loggedInUser;
    }

    public boolean IsUserLoggedIn(){
        if (this.loggedInUser != null)
            return true;
        else
            return false;
    }

    public List<Book> getBooks() {
        return books;
    }

    public List<Movie> getMovies() {
        return movies;
    }

    public List<Reservation> getReservations() {
        return reservations;
    }

    public void loadBooksIntoMemory(){
        Book b1 = new Book(1,"Jurassic Park","Michael Chriton");
        Book b2 = new Book(2,"Twilight","Some Cougar Woman");
        Book b3 = new Book(3,"Kamasutra","Mr Old Dude");
        Book b4 = new Book(4,"The Great Gatsby","F Scott Fitzgerald");
        this.books.add(b1);
        this.books.add(b2);
        this.books.add(b3);
        this.books.add(b4);
    }

    public void loadMoviesIntoMemory(){
        Movie m1 = new Movie(1,"Terminator 2", "1991", "James Cameron","10");
        Movie m2 = new Movie(2,"The Godfather", "1972", "Francis Ford Coppola","9");
        Movie m3 = new Movie(3,"The Matrix", "1999", "Wachowskies","9");
        Movie m4 = new Movie(4,"Psycho", "1960", "Alfred Hitchcock","7");
        Movie m5 = new Movie(5,"The Lone Ranger", "2013", "Gore Verbinski","");
        Movie m6 = new Movie(6,"Aliens", "1986", "James Cameron","8");
        Movie m7 = new Movie(7,"Jurassic Park", "1996", "GSteven Spielberg","9");
        Movie m8 = new Movie(8,"Batman Begins", "2005", "Christopher Nolan","9");
        Movie m9 = new Movie(9,"World War Z", "2013", "Carc Forster","");
        Movie m10 = new Movie(10,"Pulp Fiction", "1994", "Quentin Tarantino","7");
        Movie m11 = new Movie(11,"Battlefield Earth", "2000", "Roger Christian","1");
        Movie m12 = new Movie(12,"The Shawshank Redemption", "1994", "Frank Darabont","10");
        Movie m13 = new Movie(13,"The Usual Suspects", "1995", "Bryan Singer","9");
        Movie m14 = new Movie(14,"Sin City", "2005", "Frank Miller","8");
        Movie m15 = new Movie(15,"Zoolander", "2001", "GBen Stiller","9");
        this.movies.add(m1);this.movies.add(m2);this.movies.add(m3);
        this.movies.add(m4); this.movies.add(m5);this.movies.add(m6);
        this.movies.add(m7);this.movies.add(m8);this.movies.add(m9);
        this.movies.add(m10);this.movies.add(m11);this.movies.add(m12);
        this.movies.add(m13);this.movies.add(m14);this.movies.add(m15);
    }

    public boolean addReservation(Reservation reservation){
        return this.reservations.add(reservation);
    }

    public String ListAllBooks(){
        StringBuilder result = new StringBuilder();

        for(Book b:this.books)
            result.append(b.toString()+"\n");

        return result.toString();
    }

    public String ListAllMovies(){
        StringBuilder result = new StringBuilder();

        result.append(String.format("%-25s %-5s %-25s %-6s\n", "Movie", "Year", "Director", "Rating"));
        for(Movie m:this.movies)
            result.append(m.toString()+"\n");

        return result.toString();
    }

}


